﻿using System.Linq;
using System.Threading.Tasks;
using Castle.DynamicProxy;

namespace Extensions.Interceptor.Cache.Keys;

public class RetrunTypeStrategy:BaseStrategy
{
    public override KeyStrategyEnum KeyStrategyEnum { get; set; } = KeyStrategyEnum.RetrunType;
    public override string GetKey(IInvocation invocation)
    {
        var method = invocation.MethodInvocationTarget ?? invocation.Method;
       
        if (typeof(Task).IsAssignableFrom(method.ReturnType))
        {
            return string.Join("", method.ReturnType.GetGenericArguments().Select(p => p.Name)) ;
        }
        return method.ReturnType.Name;
    }
}